{% load humanize %}
<div class="race">
    <ol>
    {% for candidate in race.candidate_set.all %}
      <li class="{% ifequal race.greenest candidate %}greenest{% endifequal %}">
        {% ifequal race.greenest candidate  %}
          <img src="/public/images/world.png" alt="Most endorsed by environmental groups" title="Most endorsed by environmental groups" class="badge"/>
        {% endifequal %}

        {% ifequal race.winner candidate %}
          <img src="/public/images/star.png" alt="{% if race.projected %}Projected {% endif %}Winner" title="{% if race.projected %}Projected {% endif %}Winner" class="badge"/>
          {% if race.projected %} (projected){% endif %}
        {% endifequal %}
        {{candidate.name}} ({{candidate.party_abbv}})

        {% for endorsement in candidate.endorsement_set.all %}
        {% ifequal forloop.counter 1 %}<ul>{% endifequal %}
            <li><a href="{{endorsement.url}}">{{endorsement.organization.name}}</a></li>
        {% ifequal forloop.counter candidate.endorsement_set.all.count %}</ul>{% endifequal %}
        {% endfor %}


      </li>
    {% endfor %}
    </ol>
    
  {% if race.winner %}
    {% if race.tally_notes %}
        <p class="tally-notes">{{race.tally_notes}}</p>
    {% endif %}
    {% if race.tally_updated %}
        <p class="tally-updated">Updated {{race.tally_updated|naturalday}} at {{race.tally_updated|date:"h:i a"}}</p>
    {% endif %}
  {% else %}
    <p class="tally-notes">Results are not yet available for this race.</p>
  {% endif %}
</div>
